<?php

namespace app\models;

use app\models\FictionChapter;
use yii\db\ActiveRecord;
use Yii;

class FictionChapter extends ActiveRecord{
	
	
	public static function tableName(){
		// return "shop_admin";
		return "{{%FictionChapter}}";
	}

	public function rules(){

    }

    public function attributeLabels(){
        return [
            'fId' => '小说id',
            'fBook' => '小说对应卷',
            'fChapter' => '小说对应章',
            'fChapterName' => '对应章的标题',
        ];
    }
    
    //插入数据
    public function insertFiction($data){
        //load是php框架内部自主加载数据的函数，而validate是自主验证rules
    }

    //根据fid获取某一小说全部信息
    //卷、章、章节标题
    public function getChapter($fId, $fBook){
        $data = self::find()->select(['fBook','fChapter','fChapterName'])->where('fId = :fId and fBook = :fBook',[':fId'=>$fId,':fBook'=>$fBook])->asArray()->all();
        return $data;
    }

    //根据fid、fBook、fCharter获取章节名字
    //与漫画不同，漫画是一话一个标题，而小说是一卷然后许多个章节（带名称）
    //卷、章、章节标题
    public function getChapterName($fId, $fBook, $fChapter){
        $data = self::find()->select(['fBook','fChapter','fChapterName'])->where('fId = :fId and fBook = :fBook and fChapter = :fChapter',[':fId'=>$fId,':fBook'=>$fBook,':fChapter'=>$fChapter])->asArray()->one();
        return $data;
    }
}
